package com.x.chalk.service.impl;

import com.x.chalk.dao.CommentDao;
import com.x.chalk.dto.CommentDto;
import com.x.chalk.entity.Comment;
import com.x.chalk.service.intf.CommentService;
import com.x.chalk.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Author FSir
 * @create 2022/10/5 16:43
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentDao commentDao;
    @Override
    public R add(CommentDto dto,String token) {
        if (Objects.nonNull(dto)){
            long uid = Long.parseLong(token);
            commentDao.insert(new Comment(uid,dto.getMid(), dto.getInfo(),0L));
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public R reply(CommentDto dto,String token) {
        if (Objects.nonNull(dto)){
            long uid = Long.parseLong(token);
            commentDao.insert(new Comment(uid,dto.getMid(), dto.getInfo(),dto.getPid()));
            return R.ok();
        }
        return R.fail();
    }
}
